﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.LoadedPmiTypes.CUiLoadedPmiTypesFlexGrid
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using C1.Win.C1FlexGrid;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui48;


namespace DnProcessSimulateCommands.LoadedPmiTypes;

internal class CUiLoadedPmiTypesFlexGrid : TxFlexGridExtension
{
  private List<TxPmiType> m_basePmiTypes;

  private List<TxPmiType> BasePmiTypes
  {
    get
    {
      if (this.m_basePmiTypes == null)
        this.m_basePmiTypes = TxPmiType.GetBasePmiTypes();
      this.FilterPmiTypesInRobotExpert(this.m_basePmiTypes);
      return this.m_basePmiTypes;
    }
  }

  public void Init(TxFlexGrid oppositeGrid) => ((Control) this).Tag = (object) oppositeGrid;

  public List<Node> SelectedNodes()
  {
    List<Node> selectedNodes = new List<Node>();
    CellRange selection = ((C1FlexGridBase) this).Selection;
    if (((CellRange) ref selection).IsValid)
    {
      foreach (Node nodes in this.NodesList())
      {
        if (((RowCol) nodes.Row).Selected)
          selectedNodes.Add(nodes);
      }
    }
    selectedNodes.RemoveAll((Predicate<Node>) (node =>
    {
      bool flag = false;
      return node.Parent != null && selectedNodes.Exists((Predicate<Node>) (n => TxPmiType.op_Equality(n.PmiType(), node.Parent.PmiType()))) || flag;
    }));
    return selectedNodes;
  }

  public void ClearAll()
  {
    ((C1FlexGridBase) this).Clear();
    ((C1FlexGridBase) this).Rows.RemoveRange(0, ((RowColCollection) ((C1FlexGridBase) this).Rows).Count);
  }

  public bool HasSelection()
  {
    bool flag = false;
    foreach (RowCol row in (IEnumerable) ((C1FlexGridBase) this).Rows)
    {
      if (row.Selected)
      {
        flag = true;
        break;
      }
    }
    return flag;
  }

  public List<Node> NodesList()
  {
    List<Node> nodeList = new List<Node>();
    foreach (Row row in (IEnumerable) ((C1FlexGridBase) this).Rows)
      nodeList.Add(row.Node);
    return nodeList;
  }

  public CUiLoadedPmiTypesFlexGrid OppositeGrid()
  {
    return ((Control) this).Tag as CUiLoadedPmiTypesFlexGrid;
  }

  public void MoveSelectedNodes()
  {
    CellRange selection = ((C1FlexGridBase) this).Selection;
    if (!((CellRange) ref selection).IsValid)
      return;
    foreach (Node selectedNode in this.SelectedNodes())
      selectedNode.MoveToOppositeGrid();
  }

  public void LoadAllPmiTypes()
  {
    List<TxPmiType> txPmiTypeList = new List<TxPmiType>();
    foreach (Node nodes in this.NodesList())
    {
      if (nodes.Expanded)
        txPmiTypeList.Add(nodes.PmiType());
    }
    this.OppositeGrid().ClearAll();
    this.ClearAll();
    int num1 = 0;
    int num2 = 0;
    foreach (TxPmiType basePmiType in this.BasePmiTypes)
    {
      Node node1 = ((C1FlexGridBase) this).Rows.InsertNode(num1++, 0);
      node1.Image = ((TxPmiType) ref basePmiType).Icon;
      node1.Data = (object) ((TxPmiType) ref basePmiType).Name;
      node1.SetNodeData(num2++, basePmiType);
      int num3 = 0;
      foreach (TxPmiType derivedType in ((TxPmiType) ref basePmiType).GetDerivedTypes())
      {
        Node node2 = ((C1FlexGridBase) this).Rows.InsertNode(num1++, 1);
        node2.Image = ((TxPmiType) ref derivedType).Icon;
        node2.Data = (object) ((TxPmiType) ref derivedType).Name;
        node2.SetNodeData(num3++, derivedType);
      }
    }
    foreach (Node nodes in this.NodesList())
    {
      if (txPmiTypeList.Contains(nodes.PmiType()))
        nodes.Expanded = true;
    }
  }

  private void FilterPmiTypesInRobotExpert(List<TxPmiType> m_basePmiTypes)
  {
    if (TxApplication.PlatformType != 3)
      return;
    m_basePmiTypes.Remove(TxPmiType.ArcSpotWeld);
    m_basePmiTypes.Remove(TxPmiType.BeadWeld);
    m_basePmiTypes.Remove(TxPmiType.ClinchWeld);
    m_basePmiTypes.Remove(TxPmiType.DollopWeld);
    m_basePmiTypes.Remove(TxPmiType.EdgeWeld);
    m_basePmiTypes.Remove(TxPmiType.FilletWeld);
    m_basePmiTypes.Remove(TxPmiType.GrooveWeld);
    m_basePmiTypes.Remove(TxPmiType.LineWeld);
    m_basePmiTypes.Remove(TxPmiType.LineWeldBase);
    m_basePmiTypes.Remove(TxPmiType.SpotWeldBase);
    m_basePmiTypes.Remove(TxPmiType.TapeWeld);
    m_basePmiTypes.Remove(TxPmiType.ResistanceSeamWeld);
    m_basePmiTypes.Remove(TxPmiType.ResistanceSpotWeld);
    m_basePmiTypes.Remove(TxPmiType.SlotWeld);
    m_basePmiTypes.Remove(TxPmiType.SpotWeld);
  }
}
